package cn.xxi.ai.application.entity;

import cn.xxi.ai.application.constant.MessageRole;
import cn.xxi.ai.common.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class Message extends BaseEntity {

    /** 对话 */
    private Conversation conversation;

    /** 发送方 */
    private MessageRole role;

    /** 内容 */
    private String content;

    /** 实际内容 */
    private String actualContent;

    /** 数据（多态） */
    @JsonTypeInfo(
        use = JsonTypeInfo.Id.SIMPLE_NAME,
        include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
        property = "type"
    )
    private MessageData data;

    /** token 用量 */
    private Integer tokenUsage;

    /** 父消息 */
    private Message parent;

    public Message copyWithNewId(Long newId) {
        Message copy = new Message();
        copy.setId(newId);
        copy.setConversation(this.getConversation());
        copy.setRole(this.getRole());
        copy.setContent(this.getContent());
        copy.setActualContent(this.getActualContent());
        copy.setData(this.getData());
        copy.setTokenUsage(this.getTokenUsage());
        copy.setParent(this.getParent());
        return copy;
    }
}